import type { TagInfo } from '@/model'
import { defineStore } from 'pinia'
import { ref } from 'vue'


// 用户模块
export const UseTagsStore = defineStore(
  'tags-store',
  () => {

    // 用户信息
    const tagInfo = ref<TagInfo[]>([
      {
        name: '首页',
        path: '/index'
      }
    ])

    const timeTag = ref<TagInfo[]>([
      {
        name: '首页',
        path: '/index'
      }
    ])

    const getTags = async () => {
      
    }

    const setTags = (tag: TagInfo) => {
      if (tagInfo.value.length === 1&&tag.path != '/index' ) {
        tagInfo.value.push(tag)
      } else if (tagInfo.value.length === 2) { 
        if (tag.path =='/index') {
          tagInfo.value.pop()
        } else {
          tagInfo.value.pop()
          tagInfo.value.push(tag)
        }
          
      } 
    }

    const settimeTag = (tag: TagInfo) => {
      console.log(111, tag);
      
      if (timeTag.value.length === 1 || timeTag.value.length === 2) {
        timeTag.value.push(tag)
      } else if (timeTag.value.length === 3 && tag.path != '/time') {
        timeTag.value.pop()
        timeTag.value.push(tag)
      } 
    }

    return { settimeTag, timeTag,tagInfo, getTags, setTags }
  }
  , {
    persist : {
      storage: sessionStorage
    }
  }
)
